#pragma once
#ifndef MAP_MANAGER_H
#define MAP_MANAGER_H

#include "Base.h"
#include <map>
#include <string>

template<class T>
class CMapManager
{
	public:
		typedef std::map<std::string, T*> TMapResource;
	protected:
		TMapResource m_Resources;
	public:
		CMapManager();
		virtual ~CMapManager()
		{
			Destroy();
		}
		virtual T * GetResource(const std::string &Name)
		{
			TMapResource::iterator it = m_Resources.find(Name);

			if(it!=m_Resources.end())
			{
   				return m_Resources[Name];
			}

   			LOGGER->AddNewLog(ELL_ERROR, "TemplateManager: Error no existe en el mapa");
			return NULL;
		}
		virtual void AddResource(const std::string &Name, T *Resource)
		{
			TMapResource::iterator it = m_Resources.find(Name);
			if(it==m_Resources.end())
			{
				m_Resources[Name]=Resource;
			} else {
   				LOGGER->AddNewLog(ELL_ERROR, "TemplateManager: Error ya existe en el mapa");
			}
		}
		void RemoveResource(const std::string &Name)
		{
			TMapResource::iterator it = m_Resources.find(Name);

			if(it!=m_Resources.end())
			{
				CHECKED_DELETE(it->second);
				m_Resources.erase(it);
			} else {
   				LOGGER->AddNewLog(ELL_ERROR, "MapManager: Error no existe en el mapa");
			}
		}
		void Destroy()
		{
			for (TMapResource::iterator it=m_Resources.begin(); it!=m_Resources.end(); ++it)
			{
				CHECKED_DELETE(it->second);
			}
			m_Resources.clear();
		}
};
#endif